﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.ApplicationModel.Resources.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using App1.DataModel;

// The data model defined by this file serves as a representative example of a strongly-typed
// model that supports notification when members are added, removed, or modified.  The property
// names chosen coincide with data bindings in the standard item templates.
//
// Applications may use this model as a starting point and build on it, or discard it entirely and
// replace it with something appropriate to their needs.

namespace App1.Data
{

    [Windows.Foundation.Metadata.WebHostHidden]    


    /// <summary>
    /// Creates a collection of groups and items with hard-coded content.
    /// </summary>
    public sealed class DataController
    {
        private static DataController _dataController = new DataController();

        private ObservableCollection<GroupTag> _allChannels = new ObservableCollection<GroupTag>();
        public ObservableCollection<GroupTag> AllChannels
        {
            get { return this._allChannels; }
        }
 
        private ObservableCollection<GroupEvent> _Events = new ObservableCollection<GroupEvent>();
        public ObservableCollection<GroupEvent> Events
        {
            get { return this._Events; }
        }



        /* -------------------------------------------------------------------------------------- */
        /*                              Retorna tots els tags generals                              */
        /* -------------------------------------------------------------------------------------- */
        
        public static IEnumerable<GroupTag> GetChannels(string uniqueId)
        {
            if (!uniqueId.Equals("AllGroups")) throw new ArgumentException("Only 'AllGroups' is supported as a collection of groups");

            // TODO: ESBORRAR TOT AIXÒ TAN BON PUNT ESTIGUI LA BD
           
            var group1 = new GroupTag("Group-1",
                    "Canals",
                    "Diferents canals d'activitats...",
                    "Assets/DarkGray.png",
                    "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");
            group1.Tags.Add(new Tag("Cinema",
                    "Cinema",
                    "Sessions de cine, curtmetratges...",
                    "Assets/LightGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
                    ));
            group1.Tags.Add(new Tag("Musica",
                    "Música",
                    "Concerts, festivals, balls...",
                    "Assets/LightGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
                    ));
            group1.Tags.Add(new Tag("Gastronomia",
                    "Gastronomia",
                    "Tasts, festes gastronòmiques...",
                    "Assets/DarkGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
                    ));
            group1.Tags.Add(new Tag("Exposicions",
                    "Exposicions",
                    "museus, exposicions, performances",
                    "Assets/MediumGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
                    ));
            _dataController.AllChannels.Add(group1);
            return _dataController.AllChannels;
        }

        
        /* -------------------------------------------------------------------------------------- */
        /*                  Retorna els events que tinguin el tag uniqueId                          */
        /* -------------------------------------------------------------------------------------- */
        public static IEnumerable<Event> GetEvents(string uniqueId)
        {    
        
                     
            List<Tag> tags = new List<Tag>();
            tags.Add(new Tag("Musica",
                    "Música",
                    "Concerts, festivals, balls...",
                    "Assets/LightGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat."
                    ));
            
            var group2 = new GroupEvent("Group-2",
            "Esdeveniments de música",
            "Concerts, festivals, balls...",
            "Assets/DarkGray.png",
            "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");
            group2.Events.Add(new Event("Group-2-Item-0",
                    "The Blue Pie",
                    "Psicodèlic, Blues, Rock.",
                    "Assets/LightGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
                    tags));
            group2.Events.Add(new Event("Group-2-Item-1",
                    "APAC",
                    "Progressiu, Funk",
                    "Assets/LightGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
                    tags));
            group2.Events.Add(new Event("Group-2-Item-2",
                    "Pink Floyd",
                    "Psicodèlic, Progressiu",
                    "Assets/DarkGray.png",
                    "Item Description: Pellentesque porta, mauris quis interdum vehicula, urna sapien ultrices velit, nec venenatis dui odio in augue. Cras posuere, enim a cursus convallis, neque turpis malesuada erat, ut adipiscing neque tortor ac erat.",
                    tags));
            _dataController.Events.Add(group2);

            return _dataController._Events.SelectMany(group => group.Events).Where((item) => item.Channels.Any(x => x.UniqueId.Equals(uniqueId)));

        }


        /* -------------------------------------------------------------------------------------- */
        /*                  Retorna un Tag donada la seva id                                        */
        /* -------------------------------------------------------------------------------------- */
       public static Tag GetChannel(string uniqueId)
        {
            // Simple linear search is acceptable for small data sets
            var matches = _dataController.AllChannels.SelectMany(group => group.Tags).Where((channel) => channel.UniqueId.Equals(uniqueId));
            if (matches.Count() == 1) return matches.First();
            return null;
        }

        public static Event GetItem(string uniqueId)
        {
            // Simple linear search is acceptable for small data sets
            var matches = _dataController._Events.SelectMany(group => group.Events).Where((item) => item.UniqueId.Equals(uniqueId));
            if (matches.Count() == 1) return matches.First();
            return null;
        }

        public DataController()
        {            
                      
        }
    }
}
